﻿@{
    Layout = null;
}
<!DOCTYPE html>

<html lang="zh">
<head>
    <meta charset="utf-8" />
    <title>产品管理</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
    <!--SEO优化部分-->
    @Html.Partial("_Title")
    <!--全局样式部分-->
    @*@Html.Raw(ViewBag.CssFile)*@
    <link href="~/Theme/layui/css/layui.css" rel="stylesheet" />
    <link href="/Theme/plugins/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/Theme/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css" />
    <link href="/Theme/css/style.css" rel="stylesheet" type="text/css" />
    <link href="/Theme/css/style-responsive.css" rel="stylesheet" type="text/css" />
    <link href="/Theme/css/themes/default.css" rel="stylesheet" type="text/css" />
    <link href="/Theme/plugins/Flexigrid/css/flexigrid.css" rel="stylesheet" />
    <script src="~/Theme/My97DatePicker/WdatePicker.js"></script>
    <script src="~/Theme/layui/laypage.js"></script>
    <style>

        html {
        width:100%;
        height:100%;
        overflow:hidden;
        }


    </style>
</head>
<body class="fixed-top" >
    <!--头部-->
    @Html.Partial("_Top")
    <div id="container" class="row-fluid true" >
        <!--左侧菜单-->
        @Html.Partial("_LeftMenu")
        <div id="body">
            <div class="container-fluid">
                <div class="row-fluid">
                    <div class="span12">    

                    </div>
                </div>
                <div class="row-fluid" >
                    <div class="span12">
                        <div class="widget box light-grey">
                            <div class="widget-title">
                                <h4><i class="icon-globe"></i>产品管理</h4>

                                <div class="actions">
                                    <div id="batchUpdate" class="btn-group ">
                                        <button class="btn btn-success dropdown-toggle" data-toggle="dropdown">批量修改<span class="caret"></span></button>
                                        <ul class="dropdown-menu">
                                            <li><a href="#">产品标题</a></li>
                                            <li><a href="#">产品属性</a></li>
                                            <li><a href="#">可售数量</a></li>
                                            <li><a href="#">产品价格</a></li>
                                            <li><a href="#">价格区间</a></li>
                                            <li><a href="#">最小起订量</a></li>
                                            <li><a href="#">有效期</a></li>
                                            <li><a href="#">混批设置</a></li>
                                            <li><a href="#">自定义分类</a></li>
                                            <li><a href="#">主图顺序</a></li>
                                            <li><a href="#">产品主图</a></li>
                                            <li><a href="#">发货地址</a></li>
                                            <li><a href="#">运费信息</a></li>
                                            <li><a href="#">图片/价格私密</a></li>
                                            <li><a href="#">详细描述</a></li>
                                        </ul>
                                    </div>
                                    <a class="btn btn-danger" href="javascript:void(0)" onclick="Product.BatchDel()"><i class="icon-trash"></i>&nbsp;复制</a>
                                    <a class="btn btn-primary" href="javascript:void(0)" onclick="Product.Add()"><i class="icon-pencil"></i>&nbsp;下架</a>
                                    <a class="btn btn-info" href="javascript:void(0)" onclick="Product.ToExcel()"><i class="icon-download"></i>&nbsp;上架</a>
                                    <a class="btn btn-primary" href="javascript:void(0)" onclick="Product.Add()"><i class="icon-pencil"></i>&nbsp;新增</a>
                                    <a class="btn btn-danger" href="javascript:void(0)" onclick="Product.BatchDel()"><i class="icon-trash"></i>&nbsp;删除</a>
                                    <a class="btn btn-primary" href="javascript:void(0)" onclick="Product.Add()"><i class="icon-pencil"></i>&nbsp;违禁词检测</a>
                                    <a class="btn btn-danger" href="javascript:void(0)" onclick="Product.BatchDel()"><i class="icon-trash"></i>&nbsp;一键备份</a>
                                </div>
                            </div>
                            @*<div class="widget-title">
                                <h4><i class="icon-globe"></i>产品管理hh</h4>
                            </div>*@

                            <div class="widget-body" style="max-height:550px; overflow:auto;">
                                <div class="row-fluid">
                                    <form class="form-horizontal" action="javascript:void(0)">
                                        <div class="control-group">
                                            <div class="controls controls-cus">
                                                <input id="txtSearch" type="text" class="input-xlarge" placeholder="请输入标题/货号">
                                                <a id="gritter-remove-all" class="btn btn-info" href="javascript:void(0)" onclick="SearchPro(1,1)"><i class="icon-search"></i>&nbsp;搜索</a>
                                                <div class="btn-group open">
                                                    <button id="btnHSearch" data-toggle="dropdown" class="btn btn-primary dropdown-toggle">高级搜索 <span class="caret"></span></button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <div id="divHSearch" class="row-fluid hide" style="display:none;">
                                    <div class="widget">
                                        <div class="widget-body form">
                                            <form class="horizontal-form" action="javascript:void(0)">
                                                <div class="row-fluid">

                                                    <div class="span2">
                                                        <div class="control-group">
                                                            <label for="firstName" class="control-label">星级质量</label>
                                                            <div class="controls">
                                                                <select id="qualityLevel" class="input-medium">
                                                                    <option value="">全部星级</option>
                                                                    <option value="1">1星级</option>
                                                                    <option value="2">2星级</option>
                                                                    <option value="3">3星级</option>
                                                                    <option value="4">4星级</option>
                                                                    <option value="5">5星级</option>
                                                                </select>&nbsp;&nbsp;
                                                                <span class="help-block"></span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="span2">
                                                        <div class="control-group">
                                                            <label for="firstName" class="control-label">产品类型</label>
                                                            <div class="controls">
                                                                <select id="category" name="ddlDepart" class="input-medium">
                                                                    <option value="000000">请选择类目</option>
                                                                    <option value="000001">数码</option>
                                                                    <option value="000002">化工</option>
                                                                    <option value="000003">家电</option>
                                                                </select>
                                                                <span class="help-block"></span>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <div>

                                                        <label for="firstName" class="control-label">发布日期</label>
                                                        <input id="gmtModifiedBegin" type="text" class="">
                                                        <span class="">至</span>
                                                        <input id="gmtModifiedEnd" type="text" class="">

                                                        <a class="btn btn-info" href="javascript:void(0)" onclick="SearchPro(2,1)"><i class="icon-search"></i>&nbsp;搜索</a>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                                <table class="table table-striped table-bordered table-hover" id="tabInfo">
                                    <thead>
                                        <tr class="widget-title">
                                            <th style="width: 8px;"><input type="checkbox" class="group-checkable" onclick="Product.SelectAll(this)"></th>
                                            <th class="hidden-480">状态</th>
                                            <th class="hidden-480">图片</th>
                                            <th class="hidden-480">产品标题</th>
                                            <th class="hidden-480">价格区间</th>
                                            <th class="hidden-480">产品星级</th>
                                            <th class="hidden-480">发布时间</th>
                                            <th class="hidden-480">过期时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="Prolist"></tbody>
                                </table>

                            </div>
                        </div>
                        </div>
                   
                    </div>
                
                </div>
            <div class="" id="mypager"></div>
           </div>
    </div>

    <!--底部样式-->
    @*@Html.Partial("_Foot")*@

    <script type="text/javascript">

        //时间插件初始化
        $(function () {
            $("#gmtModifiedBegin").attr('placeholder', '起始日期');
            $("#gmtModifiedEnd").attr('placeholder', '截止日期');
            $("#gmtModifiedBegin").bind("click", function () {
                var endT = $('#gmtModifiedEnd').val();
                if (endT == "") {
                    WdatePicker({ doubleCalendar: true, startDate: '#F{\'gmtModifiedEnd\'&&$dp.$D(\'gmtModifiedEnd\',{d:-50})||\'%yd\'}', minDate: '#F{\'gmtModifiedEnd\'&&$dp.$D(\'gmtModifiedEnd\',{d:-50})}', dateFmt: 'yyyy-MM-dd', autoPickDate: true, lang: 'zh-tw', onpicked: function () { $('#gmtModifiedEnd').trigger('click'); } });
                }
                else {
                    WdatePicker({ doubleCalendar: true, startDate: '#F{\'gmtModifiedEnd\'&&$dp.$D(\'gmtModifiedEnd\')||\'%y\'}', dateFmt: 'yyyy-MM-dd', autoPickDate: true, maxDate: '#F{$dp.$D(\'gmtModifiedEnd\')}', lang: 'zh-tw' });
                }

            });
            $("#gmtModifiedEnd").bind("click", function () {
                WdatePicker({ doubleCalendar: true, startDate: '#F{$dp.$D(\'gmtModifiedBegin\')||\'%y\'}', minDate: '#F{$dp.$D(\'gmtModifiedBegin\')}', dateFmt: 'yyyy-MM-dd', autoPickDate: true, lang: 'zh-tw' });
            });
        });

        //当页面加载完成
        $(function () {

            //初次加载数据
            SearchPro(1,1);

            //高级搜索，隐藏&显示
            $("#btnHSearch").click(function () {
                var flag = $("#divHSearch").css("display");
                if (flag == "none") {
                    $("#txtHOrderNum").val("");
                    $("#txtHBeginTime").val("");
                    $("#txtHEndTime").val("");
                    $("#divHSearch").slideDown("slow");
                } else {
                    $("#divHSearch").slideUp("slow");
                }
            });

            //点击批量管理
            $("#batchUpdate").bind("click", function () {
                //显示隐藏元素
                $(".dropdown-menu").slideToggle();
            })
        })

        //搜索产品
        var SearchPro = function (type, PageIndex) {
            var Searchparameter = new Object();
            Searchparameter["txtSearch"] = $("#txtSearch").val();
            Searchparameter["PageIndex"] = PageIndex;//请求页

            if (type == 1) {
                RequestProList(Searchparameter);
            }
            else {
                Searchparameter["qualityLevel"] = $("#qualityLevel").val();
                Searchparameter["category"] = $("#category").val();
                Searchparameter["gmtModifiedBegin"] = $("#gmtModifiedBegin").val();
                Searchparameter["gmtModifiedEnd"] = $("#gmtModifiedEnd").val();

                //请求产品数据集合
                RequestProList(Searchparameter);
            }

        }

        //前端储存的产品集合
        var Allproducts = new Array();
        //请求数据，解析数据，异步加载要显示的产品数据列表        
        function RequestProList(Searchparameter)
        {
            //提示弹层
            layer.msg('正在加载数据...', { icon: 16, shade: [0.5, '＃f5f5f5'], scrollbar: false, offset: '300px', time: 50000 });

            $.ajax({
                url: "/Product/RequestProList",
                data: Searchparameter,
                success: function (data) {

                    //解析产品集合    
                    var objs = JSON.parse(data);
                    var Currentcount = objs["Currentcount"];
                    var products = objs["products"];

                    //储存集合
                    PushProducts(products);

                    var htmls = "";
                    for (var i = 0; i < products.length; i++) {
                        
                        htmls += "<tr class='odd gradeX'>"
                        htmls += "<td><input type='checkbox' name='user_item' class='checkboxes' data='000001' value='000001'></td>";
                        htmls += "<td>销售中</td>";
                        //htmls += "<td><img  src='https://cbu01.alicdn.com/"+products[i]["Proimage"]+"' style='width:60px; height:60px;'/></td>";
                        htmls += "<td><img  src='" + products[i]["Proimage"] + "' style='width:60px; height:60px;'/></td>";
                        htmls += "<td><a href='" + products[i]["detailsUrl"] + "' target='_blank' >" + products[i]["subject"] + "</a></td>";
                        htmls += "<td>" + products[i]["priceRanges"] + "</td>";
                        htmls += "<td>" + products[i]["qualityLevel"] + "</td>";
                        htmls += "<td>" + products[i]["gmtLastRepost"] + "</td>";
                        htmls += "<td>" + products[i]["gmtExpire"] + "</td>";
                        htmls += " <td>";
                        htmls +=      " <a class='icon-edit' href='javascript:void(0)' onclick='Product.Add(&#39;000001&#39;)' title='编辑'>";
                        htmls +=      " </a>&nbsp;&nbsp;<a class='icon-remove' href='javascript:void(0)' onclick='Product.Delete(&#39;000001&#39;)' title='删除'></a>";
                        htmls += " </td>";
                        htmls += "</tr>"  
                    }
                    $("#Prolist").html(htmls);

                    //如果请求的是第一页，重新绑定分页
                    if (Searchparameter["PageIndex"] == "1")
                    {
                        SearchList(20, Currentcount, "mypager");
                    }

                    //关闭弹层提示
                    layer.closeAll();
                }

            })
        }

        //分页部分脚本。
        var SearchList = function (nums, Currentcount, tagetobjectId) {

            //nums每页出现的数量
            //Currentcount 总数量
            var pages = Math.ceil(Currentcount / nums); //得到总页数
            var isone = true;
            laypage({
                cont: tagetobjectId, //容器。值支持id名、原生dom对象，jquery对象,
                pages: pages, //总页数
                pagination: Currentcount,
                skip: true, //是否开启跳页
                skin: '#3c88fe',
                groups: 3, //连续显示分页数
                curr: function (obj) {
                    isone = false;
                }(),
                jump: function (obj) {

                    if (isone) {

                        $("#" + tagetobjectId + "").attr("pageIndex", obj.curr)

                        //请求数据。
                        //getParent(true, tagetobjectId, false);
                        SearchPro(2,obj.curr);
                    }
                    else {

                        isone = true;
                    }
                }
            });
        }

        //储存产品对象的方法。
        var PushProducts = function (products)
        {
            for (var i = 0; i < products.length; i++) {

                var on = 0
                for (var r = 0; r < Allproducts.length; r++) {

                    if (Allproducts[r]["offerId"] == products[i]["offerId"])
                    {
                        on++;
                    }
                }
                if (on ==0)
                {
                    Allproducts.push(products[i]);
                }
                on = 0;
            }
        }

        //批量操作弹出
        var ProOperation = function (name)
        {
            switch (name)
            {
                case "ddd":
                    SearchList();
                    break; 
                case "cc":
                    SearchList()
                    break;
            }

        }
    </script>
</body>
</html>
